<?php
$title = 'Tableau de bord';
$this->headTitle($title);

///////////////// METEO /////////////////
$meteoImg = "interrogation-32.png";
if($meteoDay) {
    if($meteoDay['type'] == 1) {
        $meteoImg = "soleil.png";
    } elseif($meteoDay['type'] == 2) {
        $meteoImg = "nuage-soleil.png";
    } elseif($meteoDay['type'] == 3) {
        $meteoImg = "nuage-pluie.png";
    } elseif($meteoDay['type'] == 4) {
        $meteoImg = "neige.png";
    }
}
        
///////////////// CHIFFRE D'AFFAIRES /////////////////
// Date of last day
$dayDate = $caJour['orderDate'];
$dayDate = new \DateTime($caJour['orderDate']); 

// CA Mois
$ca_ttc_mois = ($caMois['ca_ttc'])?$caMois['ca_ttc']:0;
$ca_ht_mois = ($caMois['ca_ht'])?$caMois['ca_ht']:0;

// CA Jour
$ca_ttc_jour = ($caJour['ca_ttc'])?$caJour['ca_ttc']:0;
$ca_ht_jour = ($caJour['ca_ht'])?$caJour['ca_ht']:0;

// CA Totalité
$ca_ttc_tout = ($caTout['ca_ttc'])?$caTout['ca_ttc']:0;
$ca_ht_tout = ($caTout['ca_ht'])?$caTout['ca_ht']:0;

// Pourcentage CA
$prcCaTtcJ = ($ca_ttc_jour*100)/$ca_ttc_tout;
$prcCaHtJ = ($ca_ht_jour*100)/$ca_ttc_tout;
$prcCaTtcM = ($ca_ttc_mois*100)/$ca_ttc_tout;
$prcCaHtM = ($ca_ht_mois*100)/$ca_ttc_tout;

///////////////// TICKET MOYEN /////////////////
$tm_jour = ($tmTtcJour['nombre']!=0)?($tmTtcJour['valeur']/$tmTtcJour['nombre']):0;
$tm_mois = ($tmTtcMois['nombre']!=0)?($tmTtcMois['valeur']/$tmTtcMois['nombre']):0;
$tm_tout = ($tmTtcTout['nombre']!=0)?($tmTtcTout['valeur']/$tmTtcTout['nombre']):0;

// Pourcentage TM
$prcTmJ = ($tm_jour*100)/$tm_tout;
$prcTmM = ($tm_mois*100)/$tm_tout;

///////////////// TICKET MOYEN /////////////////
// Repas Mois
$repas_mois = ($repasMois['repas'])?$repasMois['repas']:0;

// Repas Jour
$repas_jour = ($repasJour['repas'])?$repasJour['repas']:0;

// Repas Totalité
$repas_tout = ($repasTout['repas'])?$repasTout['repas']:0;

// Pourcentage Repas
if($repas_tout > 0) {
    $prcRepasJ = ($repas_jour*100)/$repas_tout;
    $prcRepasM = ($repas_mois*100)/$repas_tout;
} else {
    $prcRepasJ = 0;
    $prcRepasM = 0;
}

///////////////// ECARTS CAISSES /////////////////
// Annulation Jour
$ec_jour = ($ecartDay['ec'])?$ecartDay['ec']:0;

// Annulation Mois
$ec_mois = ($ecartMonth['ec'])?$ecartMonth['ec']:0;

///////////////// TRANSACTIONS ET VENTES /////////////////
// T&V Jour
$nbt_jour = ($nbTJour['nbTransaction'])?$nbTJour['nbTransaction']:0;
$nba_jour = ($nbAJour['nbArticle'])?$nbAJour['nbArticle']:0;

// T&V Mois
$nbt_mois = ($nbTMois['nbTransaction'])?$nbTMois['nbTransaction']:0;
$nba_mois = ($nbAMois['nbArticle'])?$nbAMois['nbArticle']:0;

// T&V Totalité
$nbt_tout = ($nbTTout['nbTransaction'])?$nbTTout['nbTransaction']:0;
$nba_tout = ($nbATout['nbArticle'])?$nbATout['nbArticle']:0;

// Pourcentage T&V
if($nbt_tout > 0) {
    $prcNbtJ = ($nbt_jour*100)/$nbt_tout;
    $prcNbtM = ($nbt_mois*100)/$nbt_tout;
} else {
    $prcNbtJ = 0;
    $prcNbtM = 0;
}

if($nba_tout > 0) {
    $prcNbaJ = ($nba_jour*100)/$nba_tout;
    $prcNbaM = ($nba_mois*100)/$nba_tout;
} else {
    $prcNbaJ = 0;
    $prcNbaM = 0;
}
?>
<div class="content-head">
    <h3>Tableau de bord</h3>
</div>
<div class="content-body">
    <table class="page-content">
        <tr>
            <td class="perimetre-title"><div class="rotate-90"><?php echo $store->name; ?></div></td>
            <td class="perimetre-content">
                <div class="pc-top">
                    <table>
                        <tr>
                            <td width="10%" class="pc-top-left"><p>Période</p></td>
                            <td width="90%" class="pc-top-right"><p><?php echo $periodText; ?></p></td>
                        </tr>
                    </table>
                </div>
                <div class="pc-head">
                    <table>
                        <tr>
                            <td width="10%" style="padding-left: 10px; color: red">Rubriques</td>
                            <td width="30%">
                                <p><label><input type="checkbox" class="styled" id="mo" /> Main d'oeuvre</label></p>
                                <p><label><input type="checkbox" class="styled" id="tsf" /> Transferts</label></p>
                                <p><label onclick="showRubrique(this);">
                                        <input type="checkbox" class="styled" id="ca" checked="checked" /> Chiffres d'affaire</label></p>
                                <p><label onclick="showRubrique(this);">
                                        <input type="checkbox" class="styled" id="ec" checked="checked" /> Ecarts caisse</label></p>
                            </td>
                            <td width="30%">
                                <p><label onclick="showRubrique(this);">
                                        <input type="checkbox" class="styled" id="popr" checked="checked" /> Pertes / Offerts / Personnel repas</label></p>
                                <p><label><input type="checkbox" class="styled" id="ac" /> Annulation caisse</label></p>
                                <p><label onclick="showRubrique(this);">
                                        <input type="checkbox" class="styled" id="mt" checked="checked" /> Météo</label></p>
                                <p><label onclick="showRubrique(this);">
                                        <input type="checkbox" class="styled" id="tv" checked="checked" /> Transactions et ventes</label></p>
                            </td>
                            <td width="30%">
                                <p><label><input type="checkbox" class="styled" id="bq" /> Banques</label></p>
                                <p><label><input type="checkbox" class="styled" id="cc" /> Comptes clients</label></p>
                                <p><label><input type="checkbox" class="styled" id="rc" /> Ratio clefs</label></p>
                                <p><label><input type="checkbox" class="styled" id="all" /> Tout décocher</label></p>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="pc-content">
                    <div class="retour"><a href="<?php echo $this->url('operation/default') ?>"><img border="0" width="32" src="<?php echo $this->basePath() . '/img/operation/retour.png'; ?>" /></a></div>
                    <table>
                        <tr>
                            <td class="synth-jour">
                                <div class="synth-wrapper">
                                <div>
                                    <table>
                                        <tr>
                                            <td class="pc-content-head-title">Synthèse jour (<?php echo $dayDate->format('d M Y'); ?>)</td>
                                            <td class="pc-content-head-icons" style="width:32px;height:32px"><img class="mt" width="32" src="<?php echo $this->basePath() . '/img/operation/'.$meteoImg; ?>" /></td>
                                        </tr>
                                    </table>
                                </div>
                                <div>
                                    <table class="synth-table">
                                        <tr>
                                            <th width="32%"></th>
                                            <th width="17%" class="lib-top">Valeur</th>
                                            <th width="17%" class="lib-top">%</th>
                                            <th width="17%" class="lib-top">Budget</th>
                                            <th width="17%" class="lib-top">Ecart</th>
                                        </tr>
                                        <tr class="rubTr tv">
                                            <td width="32%" class="lib-left">Productivité</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($nba_jour,0,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcNbaJ,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr ca">
                                            <td width="32%" class="lib-left">CA TTC</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($ca_ttc_jour,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcCaTtcJ,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr ca">
                                            <td width="32%" class="lib-left">CA HT</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($ca_ht_jour,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcCaHtJ,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr tv">
                                            <td width="32%" class="lib-left">Transactions</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($nbt_jour,0,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcNbtJ,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr tm">
                                            <td width="32%" class="lib-left">Ticket Moyen</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($tm_jour,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcTmJ,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr ec">
                                            <td width="32%" class="lib-left">Ecarts caisses</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($ec_jour,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr popr">
                                            <td width="32%" class="lib-left">Repas</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($repas_jour,0,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcRepasJ,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>                                        
                                    </table>
                                </div>
                                </div>
                            </td>
                            <td class="synth-mois">
                                <div class="synth-wrapper">
                                <div>
                                    <table>
                                        <tr>
                                            <td class="pc-content-head-title">Synthèse mois</td>
                                            <td class="pc-content-head-icons"><img width="32" src="<?php echo $this->basePath() . '/img/operation/soleil.png'; ?>" /></td>
                                            <td class="pc-content-head-icons value">
                                                <?php 
                                                $nbtype1 = 0;
                                                foreach($meteoMonth as $metM):
                                                    if($metM['type'] == 1):
                                                        $nbtype1 = $metM['nbMeteo'];
                                                    endif;
                                                endforeach;
                                                echo '<span class="mt">'.$nbtype1.'</span>';
                                                ?>
                                            </td>
                                            <td class="pc-content-head-icons"><img width="32" src="<?php echo $this->basePath() . '/img/operation/nuage-soleil.png'; ?>" /></td>
                                            <td class="pc-content-head-icons value">
                                                <?php 
                                                $nbtype2 = 0;
                                                foreach($meteoMonth as $metM):
                                                    if($metM['type'] == 2):
                                                        $nbtype2 = $metM['nbMeteo'];
                                                    endif;
                                                endforeach;
                                                echo '<span class="mt">'.$nbtype2.'</span>';
                                                ?>
                                            </td>
                                            <td class="pc-content-head-icons"><img width="32" src="<?php echo $this->basePath() . '/img/operation/nuage-pluie.png'; ?>" /></td>
                                            <td class="pc-content-head-icons value">
                                                <?php 
                                                $nbtype3 = 0;
                                                foreach($meteoMonth as $metM):
                                                    if($metM['type'] == 3):
                                                        $nbtype3 = $metM['nbMeteo'];
                                                    endif;
                                                endforeach;
                                                echo '<span class="mt">'.$nbtype3.'</span>';
                                                ?>
                                            </td>
                                            <td class="pc-content-head-icons"><img width="32" src="<?php echo $this->basePath() . '/img/operation/neige.png'; ?>" /></td>
                                            <td class="pc-content-head-icons value">
                                                <?php 
                                                $nbtype4 = 0;
                                                foreach($meteoMonth as $metM):
                                                    if($metM['type'] == 4):
                                                        $nbtype4 = $metM['nbMeteo'];
                                                    endif;
                                                endforeach;
                                                echo '<span class="mt">'.$nbtype4.'</span>';
                                                ?>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div>
                                    <table class="synth-table">
                                        <tr>
                                            <th width="32%"></th>
                                            <th width="17%" class="lib-top">Valeur</th>
                                            <th width="17%" class="lib-top">%</th>
                                            <th width="17%" class="lib-top">Budget</th>
                                            <th width="17%" class="lib-top">Ecart</th>
                                        </tr>
                                        <tr class="rubTr tv">
                                            <td width="32%" class="lib-left">Productivité</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($nba_mois,0,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcNbaM,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr ca">
                                            <td width="32%" class="lib-left">CA TTC</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($ca_ttc_mois,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcCaTtcM,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr ca">
                                            <td width="32%" class="lib-left">CA HT</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($ca_ht_mois,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcCaHtM,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr tv">
                                            <td width="32%" class="lib-left">Transactions</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($nbt_mois,0,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcNbtM,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr tm">
                                            <td width="32%" class="lib-left">Ticket Moyen</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($tm_mois,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcTmM,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr ec">
                                            <td width="32%" class="lib-left">Ecarts caisses</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($ec_mois,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>
                                        <tr class="rubTr popr">
                                            <td width="32%" class="lib-left">Repas</td>
                                            <td width="17%" class="lib-value"><?php echo number_format($repas_mois,0,',', ' '); ?></td>
                                            <td width="17%" class="lib-value"><?php echo number_format($prcRepasM,2,',', ' '); ?></td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                            <td width="17%" class="lib-value">&nbsp;</td>
                                        </tr>                                        
                                    </table>
                                </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>
</div>